package com.speedchina.permission.config;

import com.speedchina.framework.inter.StandardFieldValueObtain;
import com.speedchina.permission.security.shiro.SecurityUtils;
import org.springframework.stereotype.Component;
import java.util.Date;

/**
 * @Description 为service的saveOrUpdate4AutoGenId方法提供基础属性值的设置
 * @Author xz
 * @Date 2021/4/13  13:47
 */
@Component
public class StandardFieldValueConfig implements StandardFieldValueObtain {

    @Override
    public Date getCurrentTime() {
        return new Date();
    }

    @Override
    public String getOperator() {
        String userId;
        try {
            //获取当前操作人id并返回
            userId = SecurityUtils.getLoginUser().getId();
        }catch (Exception e){
            //可能存在后台任务执行，则无需获取
            userId = null;
        }
        return userId;
    }
}